import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import HomePage from '../components/HomePage.vue'
import AboutUs from '../components/AboutUs.vue'
import LatestNews from '../components/LatestNews.vue'
import Commodity from '../components/Commodity.vue'
import CommodityInfo from '../components/CommodityInfo.vue'
import Mine from '../components/Mine.vue'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    children:[
      {
        path:'/HomePage',
        name:'HomePage',
        component:HomePage,
        meta:{ title:'首页' },
      },
      {
        path:'/AboutUs',
        name:'AboutUs',
        component:AboutUs,
        meta:{ title:'关于我们' },
      },
      {
        path:'/LatestNews',
        name:'LatestNews',
        component:LatestNews,
        meta:{ title:'最新消息' },
      },
      {
        path:'/Commodity',
        name:'Commodity',
        component:Commodity,
        meta:{ title:'商品' },
      },
      {
        path:'/CommodityInfo',
        name:'CommodityInfo',
        component:CommodityInfo,
        meta:{ title:'商品详情' },
      },
      {
        path:'/Mine',
        name:'Mine',
        component:Mine,
        meta:{ title:'我的' },
      }
    ]
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  },
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

router.beforeEach((to, from, next) => {
  window.document.title = to.meta.title as string
  next()
})

export default router
